import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { ProductService } from './product.service';
import {
  CreateProductDto,
  UpdateProductDto,
  QueryProductDto,
} from './product.dto';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';

@Controller('products')
@ApiTags('Product-商品管理')
export class ProductController {
  constructor(private readonly productService: ProductService) {}

  @Post('create')
  @ApiOperation({ summary: '创建新商品' })
  create(@Body() createProductDto: CreateProductDto) {
    return this.productService.create(createProductDto);
  }

  @Get('list')
  @ApiOperation({ summary: '分页查询商品列表' })
  findAll(@Query() queryDto: QueryProductDto) {
    return this.productService.findAll(queryDto);
  }

  @Get('getInfoById')
  @ApiOperation({ summary: '查询单个商品详情' })
  findOne(@Query('id') id: string) {
    return this.productService.findOne(id);
  }

  @Post('updateInfoById')
  @ApiOperation({ summary: '更新商品信息' })
  update(@Query('id') id: string, @Body() updateProductDto: UpdateProductDto) {
    return this.productService.update(id, updateProductDto);
  }

  @Get('setHotById')
  @ApiOperation({ summary: '设商品为热门' })
  setHotById(@Query('id') id: string, @Query('isHot') isHot: boolean) {
    return this.productService.setHotById(id, isHot);
  }

  @Get('delete')
  @ApiOperation({ summary: '删除商品' })
  remove(@Query('id') id: string) {
    return this.productService.remove(id);
  }
}
